#include <unistd.h>
#include "sys.h"
#include "PCResource.h"

static void  pc_resource_exit_callback(lv_event_t *event);

static PCResource *pc_resource;
static mutex ui_mutex;

int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        perror("bad parameter, need an ip addr");
        exit(-1);
    }

    sys_init();
    lv_init(); // lvgl gui初始化
    lv_port_disp_init();
    lv_port_indev_init();
    lv_port_fs_init();

    string ip_addr(argv[1]);

    pc_resource = new PCResource(ip_addr, 80, pc_resource_exit_callback, ui_mutex);

    while (1)
    {
        ui_mutex.lock();
        uint32_t ms = lv_task_handler();
        ui_mutex.unlock();

        usleep(ms *1000);
    }
}


/*
 *@brief picture退出回调函数
 */
static void  pc_resource_exit_callback(lv_event_t *event)
{
    delete pc_resource;
    sys_exit();

    exit(0);
}
